//
//  BaseTableViewController.m
//  iBaby365v2
//
//  Created by Kirinrin on 14-6-28.
//  Copyright (c) 2014年 suplus. All rights reserved.
//

#import "BaseTableViewController.h"
#import <MMDrawerController/MMDrawerBarButtonItem.h>
#import <UIViewController+MMDrawerController.h>

#import <TSMessage.h>

@interface BaseTableViewController ()

@end

@implementation BaseTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    
    if (!_noShowMenuButton && ![self isSubNavigation]) {
        
        MMDrawerBarButtonItem *leftDrawerButton = [[MMDrawerBarButtonItem alloc]initWithTarget:self action:@selector(leftDrawerButtonPress:)];
        [self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
    }
    
    [TSMessage setDefaultViewController:self];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)leftDrawerButtonPress:(id)sender{
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}

-(BOOL)isSubNavigation{
    if (self.navigationController){
        if ([self.navigationController.viewControllers firstObject] != self) {
            return YES;
        }
    }
    return NO;
}

@end
